package blueBridgeCup;

import java.util.Scanner;

public class demo9 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int N= in.nextInt();
        int V=in.nextInt();
        int []W=new int[N+1];
        int []v=new int[N+1];
        for (int i = 1; i <=N ; i++) {
            v[i]= in.nextInt();
            W[i]= in.nextInt();
        }
        int []dp=new int[V+1];

        for (int i = 1; i <=N ; i++) {
            for(int j=V;j>=v[i];j--){
                    dp[j]=Math.max(dp[j],dp[j-v[i]]+W[i]);
                }
        }
        System.out.println(dp[V]);
    }
}
